def calcunate_ip(ip_section):
    index = 7
    sum = 0
    while index >= 0:
        # print("ip_section=",ip_section[index])
        if ip_section[index]=="1":
            sum += 2 ** (7 - index)
        index -= 1
    return sum


def get_ip_sections(ip):
    ip_sections = []
    for i in range(4):
        each = ip[i * 8:(i + 1) * 8]
        ip_sections.append(each)
    return ip_sections


if __name__=="__main__":
    nums=int(input().strip())
    for i in range(nums):
        ip=input().strip().split()[0]
        print('.'.join(list(map(str,(map(calcunate_ip,get_ip_sections(ip)))))))





